<?php
namespace app\model;
use app\BaseModel;
use think\model\concern\SoftDelete;

class DistributionType extends BaseModel
{

    use SoftDelete;
    protected $deleteTime = 'delete_time';
    protected $defaultSoftDelete = '0000-00-00 00:00:00';
     protected $hidden = ['update_time','delete_time','sort'];

    /**
     * 搜索器
     * title多字段搜索器
     * like查询可以没有empty
     */
    public function searchTitleAttr($query,$value,$data){
        if(!empty($value)){
            $query->where('title','like','%'.$value.'%');
        }
    }
    public function searchCreateTimeAttr($query,$value,$data){
        if(!empty($value)){
            $start_time = explode(' / ',$value)[0];
            $end_time = date('Y-m-d',strtotime(explode(' / ',$value)[1])+3600*24);
            $query->where('create_time','between',[$start_time,$end_time]);
        }
    }

    protected function getAgoTimeAttr($value,$data)
    {
        return AgoTime($data['create_time']);
    }

    protected function setMultiPicAttr($value, $data)
    {
        if (is_string($value)) $value = implode(',', $value);//把前台的转换成和后台一样的数组;
        $picarr = $value;
        if (!empty($picarr) && is_array($picarr)) {
            $info = input('info/a');
            $show = input('show/a');
            $arr = array();
            foreach ($picarr as $key => $v) {
                $row['img'] = $v;
                if (!empty($info)){
                    $row['info'] = $info[$key];
                }else{
                    $row['info'] = $key+1;
                }
                $row['show'] = $show[$key];
                $arr[] = $row;
            }

            return serialize($arr);
        } else {
            return '';
        }
    }

    protected function getMultiPicAttr($value, $data)
    {
        return unserialize($value);
    }









}